package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortListDemo2 {
    public static void main(String[] args) {
        List<point> list = new ArrayList<>();
        list.add(new point(1,2));
        list.add(new point(125,2));
        list.add(new point(11,22));
        list.add(new point(14,25));
        System.out.println(list);
        Collections.sort(list, new Comparator<point>() {
            @Override
            public int compare(point o1, point o2) {
                int olen01 = o1.getX()*o1.getX()+o1.getY()*o1.getY();
                int olen02 = o2.getX()*o2.getX()+o2.getY()*o2.getY();
                return olen01-olen02;
            }
        });
        System.out.println(list);
    }
}

//class MyComparator implements Comparator<point> {
//
//    @Override
//    public int compare(point o1,point o2) {
//        int olen01 = o1.getX()*o1.getX()+o1.getY()*o1.getY();
//        int olen02 = o2.getX()*o2.getX()+o2.getY()*o2.getY();
//        return olen01-olen02;
//    }
//}
